<?php

/**
 * LogAnalysis Job
 *
 * @author tamhv@fpt.net
 */
class JobCache
{

    /**
     * Job send error message
     *
     */
    public function writeArticleCache($params)
    {
        //default return
        $response = Fpt_Server::setOutputData(0, '', '');
        try
        {
            
        }
        catch (Exception $ex)
        {
            
        }
        // Return response
        return $response;
    }

    /**
     * Clear memcached about matches
     * @param array $params
     * @return array 
     * @author QuangTM
     */
    public function clearCacheMatch($params)
    {
        // Get params
        $arrMatchesID  = $params['arrMatchesID'];
        $arrHappenDate = $params['arrHappenDate'];
        $response      = Fpt_Server::setOutputData(0, '', '');
        try
        {
            // Delete cache each match
            foreach ($arrMatchesID as $matchID)
            {
//                $memcacheInstance = Fpt_Global::getMemcacheInstance($matchID);
                $keyCache         = Fpt_Global::makeCacheKey(Match::MATCH_DETAIL, $matchID);
//                $memcacheInstance->delete($keyCache);
                Fpt_Global::deleteMemcache($matchID, $keyCache);
            }
            foreach ($arrHappenDate as $leagueID => $arrDateHappen)
            {
                foreach ($arrDateHappen as $dateHappen)
                {
                    $keyCache = Fpt_Global::makeCacheKey(Match::MATCHES_TIME, array ($dateHappen, intval($leagueID)));
                    Fpt_Global::deleteMemcache($dateHappen, $keyCache);
                }
            }
        }
        catch (Exception $ex)
        {
            Fpt_Log::sendlog(4, $ex->getCode(), $ex->getMessage(), $ex->getTraceAsString(), null, null);
        }
        return $response;
    }
    
    /**
     * Clear cache team-season (table ranking)
     * @param array $params
     * @return array
     * @author QuangTM
     */
    public function clearCacheRanking($params)
    {
        // Get params
        $seasonID = $params['seasonID'];
        $leagueID = $params['leagueID'];
        $response = Fpt_Server::setOutputData(0, '', '');
        try
        {
            // Delete cache each match
//            $memcacheInstance = Fpt_Global::getMemcacheInstance($seasonID + $leagueID);
            $keyCache = Fpt_Global::makeCacheKey(TeamSeason::TEAM_SEASON_RANKING, array($leagueID, $seasonID));
//            $memcacheInstance->delete($keyCache);
            Fpt_Global::deleteMemcache($seasonID + $leagueID, $keyCache);
        }
        catch (Exception $ex)
        {
            Fpt_Log::sendlog(4, $ex->getCode(), $ex->getMessage(), $ex->getTraceAsString(), null, null);
        }
        return $response;
    }
    
    /**
     * Clear cache top player
     * @param array $params
     * @return array 
     * @author QuangTM
     */
    public function clearCacheTopPlayer($params)
    {
        // Get params
        $seasonID = $params['seasonID'];
        $response = Fpt_Server::setOutputData(0, '', '');
        try
        {
            // Delete cache each match
//            $memcacheInstance = Fpt_Global::getMemcacheInstance($seasonID);
            $keyCache         = Fpt_Global::makeCacheKey(PlayerChampion::PLAYER_CHAMPION_BY_SEASON, $seasonID);
//            $memcacheInstance->delete($keyCache);
            Fpt_Global::deleteMemcache($seasonID, $keyCache);
        }
        catch (Exception $ex)
        {
            Fpt_Log::sendlog(4, $ex->getCode(), $ex->getMessage(), $ex->getTraceAsString(), null, null);
        }
        return $response;
    }

}
